package org.zjx.swing.controller;

import org.zjx.swing.model.LiterateModel;
import org.zjx.swing.model.MenuModel;
import org.zjx.swing.model.RecognitionModel;
import org.zjx.swing.view.*;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MenuController {
    private MenuModel model;
    private MenuView view;

    public MenuController(MenuModel model, MenuView view) {
        this.model = model;
        this.view = view;
        //setBackground();
        setButtonView();
        setListener();
    }

//    public void setBackground(){
//        view.setBackground(model.getBackgroundImage());
//    }

    public void setButtonView(){
        view.setButtonList(model.getButtonList());
    }

    public void setListener(){
        // 为按钮添加事件监听器
        view.addButtonListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JButton source = (JButton) e.getSource();
                String buttonName = source.getText();

                switch (buttonName) {
                    case "字库":
                        LiterateView literateView = new LiterateView();
                        LiterateModel literateModel = new LiterateModel();
                        LiterateController literateController = new LiterateController(literateView, literateModel);
                        literateView.setVisible(true);
                        break;
                    case "验字":
                        RecognitionView recognitionView = new RecognitionView();
                        RecognitionModel recognitionModel = new RecognitionModel();
                        RecognitionController recognitionController = new RecognitionController(recognitionModel, recognitionView);
                        recognitionView.setVisible(true);
                        break;
                    case "场景":
                        SceneView sceneView = new SceneView();
                        sceneView.setVisible(true);
                        break;
                    case "道具":
                        PropView propView = new PropView();
                        propView.setVisible(true);
                        break;
                    case "道具检验":
                        InspectView inspectView = new InspectView();
                        inspectView.setVisible(true);
                        break;
                    case "关闭窗口":
                        view.dispose();
                        break;
                    default:
                        // 可以添加对其他按钮的处理逻辑
                        break;
                }
            }
        });
    }

}
